package com.hm.ibsm.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hm.common.exception.ErrorCode;
import com.hm.common.exception.ServiceException;
import com.hm.common.network.httpclient.HttpClientFactory;
import com.hm.common.util.CommonUtil;
import com.hm.ibsm.auto.SystemSessionHolder;
import com.hm.ibsm.auto.WebProperties;
import com.hm.ibsm.auto.helper.UserSession;
import com.hm.ibsm.util.R.ReqAuthKeyDef;

/**
 * @author shishun.wang
 * @date 2017年3月7日 上午1:27:50
 * @version 1.0
 * @describe
 */
@Component
public class LocationConfig {

	@Autowired
	private WebProperties webProperties;

	public String mgUri(String uri) {
		return webProperties.getUri().getMgUrl() + uri;
	}

	public HttpClientFactory accredit(HttpClientFactory factory) {
		UserSession userSession = SystemSessionHolder.getUserSession();
		if (CommonUtil.isEmpty(userSession)) {
			throw ServiceException.warning(ErrorCode.NO_DATA_ACCESS);
		}
		return factory.headers(ReqAuthKeyDef.AUTHOR_TOKEN, userSession.getToken()).headers(ReqAuthKeyDef.AUTHORIZATION, userSession.getSecretKey());
	}
}
